// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "SimpleTypes.h"
#include "GameFramework/Actor.h"
#include "SimpleWeapon.generated.h"


class ASimpleCharacter;

UCLASS()
class SIMPLE_API ASimpleWeapon : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ASimpleWeapon();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

	FTimerHandle TimerHandle_Fire;
	
	UFUNCTION()
	void ReSetFireCD();

	uint32 bIsCanFire : 1;

	UFUNCTION(Reliable, Server, WithValidation)
	void ServerStartFire();

	UFUNCTION(Reliable, Server, WithValidation)
	void ServerStopFire();

	UPROPERTY(EditDefaultsOnly, Category = Simple)
	class USoundCue* ShootSound;

	UPROPERTY(EditDefaultsOnly, Category = Simple, Replicated)
	FWeaponData WeaponData;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Simple)
	class USceneComponent* SceneComponent;

	UPROPERTY(EditDefaultsOnly, Category = Simple)
	TSubclassOf<class ASimpleProjectile> DefaultProjectileClass;

	UFUNCTION(Reliable, Server, WithValidation)
	void ServerUpdateProjectile(int32 Damage, float ShootSpeed);
public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	virtual void StartFire();

	virtual void StopFire();

	UFUNCTION()
	void OnFire();

	UFUNCTION(BlueprintCallable, Category = Simple)
	void UpdateProjectile(int32 Damage, float ShootSpeed);

public:
	virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;

};
